package com.cjm.algorithm.leetcode;

public class IsPalindrome {
    public static boolean isPalindrome(String s) {
        if (s.length() < 1) {
            return true;
        }
        char[] chars = s.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (char aChar : chars) {
            if (isRight(aChar)) {
                if (65 <= (int)aChar && (int)aChar <= 90) {
                    sb.append((char)((int)aChar + 32));
                } else {
                    sb.append(aChar);
                }
            }
        }
        s = sb.toString();
        int i = 0;
        int j = s.length() - 1;
        while (i <= j) {
            char c = s.charAt(i++);
            char c1 = s.charAt(j--);
            if (c != c1) {
                return false;
            }
        }
        return true;
    }

    private static boolean isRight(char temp) {
        if ((48 <= (int) temp && (int) temp <= 57 )||(97 <= (int) temp && (int) temp <= 122 )|| (65 <= (int) temp && (int) temp <= 90)) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
//        System.err.println(isPalindrome("A man, a plan, a canal: Panama"));
//        System.err.println(isPalindrome("race a car"));
        System.err.println(isPalindrome("0P"));
    }
}
